<?php
include('database.php');

if($_GET['q'] == 'foody' && $_GET['rid']) {
    $groupId = intval($_GET['rid']);
    $sql = "SELECT image,username,description,date_comment FROM `group_foody_comment` WHERE point <= 5 and group_id = $groupId";
    $result = mysql_query($sql);

    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    $num_rows = mysql_num_rows($result);
    if($num_rows > 0) {
        $data = array();
        $i=0;
        while ($row = mysql_fetch_assoc($result)) {
            $data[$i]["image"] = $row["image"];
            $data[$i]["username"] = $row["username"];
            $data[$i]["description"] = $row["description"];
            $data[$i]["date_comment"] = $row["date_comment"];
            
            $i++;
        }

        mysql_free_result($result);

        echo json_encode($data);
    } else {
        
    }
}